# -*- coding:utf-8 -*-
class Solution:
    def ReverseSentence(self, s):
        # write code here、
        if not s:
            return s
        s = list(s)
        self.help(s,0,len(s)-1)
        start = 0
        e = 0
        while start<len(s):
            if s[start] == ' ':
                start+=1
                e+=1
            elif e == len(s) or s[e]==' ':
                self.help(s,start,e-1)
                e+=1
                start = e
            else:
                e+=1
        return ''.join(s)
    def help(self,s,start,e):
        while start < e:
            s[start],s[e] = s[e],s[start]
            start+=1
            e-=1

s=Solution()
print(s.ReverseSentence("I "))